using UnityEngine;
using System.Collections;

public class PlayerWalkState : State<PlayerControl>
{
    #region Singleton

    private static PlayerWalkState instance = new PlayerWalkState();
    public static PlayerWalkState Instance { get { return instance; } }
    private PlayerWalkState() { }

    #endregion
    
    #region State

    public override void OnEnter(PlayerControl behaviour)
    {
        // TODO
        // Play animation walkAnim
        // Play sound walkSound
        behaviour.PlayAnimation(AnimationConstants.PLAYER_ROLL_START);
        behaviour.MoveTo(behaviour.targetPosition, behaviour.walkSpeed);
    }

    public override void OnUpdate(PlayerControl behaviour)
    {
        behaviour.PlayAnimation(AnimationConstants.PLAYER_ROLL_COMPLETE);

        Vector3 a = new Vector3(behaviour.transform.position.x, 0, behaviour.transform.position.z);
        Vector3 b = new Vector3(behaviour.targetPosition.x, 0, behaviour.targetPosition.z);
        if (Vector3.Distance(a, b) <= behaviour.offset)
        {
            if (behaviour.doActionOnTargetPosition)
                behaviour.State = PlayerActivateSwitchState.Instance;
            else
                behaviour.State = PlayerIdleState.Instance;
        }
    }

    public override void OnExit(PlayerControl behaviour)
    {
        // TODO
        // Stop animation walkAnim
        // Stop sound walkSound
        behaviour.animation.Stop(AnimationConstants.PLAYER_ROLL_COMPLETE);
        behaviour.PlayAnimation(AnimationConstants.PLAYER_ROLL_END);
    }

    public override void OnAction(string name, PlayerControl behaviour, object value)
    {

    }

    #endregion
}
